/*
 * @Author: LiZhiWei
 * @Date: 2025-07-14 08:58:30
 * @LastEditors: wjc
 * @LastEditTime: 2025-10-28 11:00:59
 * @Description:
 */
function getUrl(str: string): string {
  return `api/admin/${str}`
}

function resources(uri: string, appends: object = {}) {
  const ob = {
    index: getUrl(uri),
    create: getUrl(`${uri}/create`),
    store: getUrl(uri),
    show: (id: number | string) => getUrl(`${uri}/${id}`),
    edit: (id: number | string) => getUrl(`${uri}/${id}/edit`),
    update: (id: number | string) => getUrl(`${uri}/${id}`),
    destroy: (id: number | string) => getUrl(`${uri}/${id}`),
    forceDestroy: (id: number | string) => getUrl(`${uri}/forever/${id}`),
    trashed: getUrl(`${uri}/trashed`),
    destroyBatch: getUrl(`${uri}/batch`),
    restoreBatch: getUrl(`${uri}/restore`),
  }
  return { ...ob, ...appends }
}

function auth() {
  const prefix = getUrl('authorizations/role/')
  return {
    index: getUrl('authorizations'),
    updateActions: (id: number | string) => `${prefix + id}/update-actions`,
    editPersonnel: (id: number | string) => `${prefix + id}/edit-personnel`,
    updatePersonnel: (id: number | string) => `${prefix + id}/update-personnel`,
    removePersonnel: (id: number | string) => `${prefix + id}/remove-personnel`,
  }
}

const api: { [key: string]: any } = {
  login: getUrl('authenticate'),
  logout: getUrl('logout'),
  Me: {
    info: getUrl('me/info'),
    language: getUrl('me/language'),
    index: getUrl('me'),
    avatar: getUrl('me/avatar'),
    password: getUrl('me/password'),
    logins: getUrl('me/logins'),
    update: (id: number | string) => getUrl(`me/${id}/update`),
  },
  LoginManagement: resources('login-managements'),
  NotifyRobot: resources('notify-robots', {
    bless: getUrl('notify-robot/bless'),
  }),
  Auth: auth(),
  Dashboard: getUrl('dashboard'),
  Notification: {
    index: getUrl('notifications'),
    makeRead: getUrl('notification/make-read'),
  },
  // User: resources('users', {
  //     // avatar: getUrl('users/avatar'),
  //     account: (id) => getUrl('users/' + id + '/account'),
  //     password: (id) => getUrl('users/' + id + '/password')
  // }),
  Personnel: resources('personnels', {
    avatar: getUrl('personnel/avatar'),
    account: (id: number | string) => getUrl(`personnel/${id}/account`),
    password: (id: number | string) => getUrl(`personnel/${id}/password`),
  }),
  Department: resources('departments', {
    move: (id: number | string) => getUrl(`department/${id}/move`),
  }),
  Position: resources('positions'),
  Role: resources('roles'),
  AppVersion: resources('app-versions'),
  AppCheckUpdate: resources('app-check-updates'),
  Timeline: resources('timelines'),
  OperationLog: resources('operation-logs'),
  TagGroup: resources('tag-groups'),
  Tag: resources('tags'),
  Page: resources('pages'),
  Region: resources('regions'),
  OneWo: resources('one-wo-htmls'),
  OneWoJobType: resources('one-wo-job-types'),
  OneWoSpace: resources('one-wo-spaces'),
  OneWoJobObject: resources('one-wo-job-objects'),
  Banner: resources('banners'),
}

export default api
